<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<section class="content-header">
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i>首页</a></li>
        <li><a href="#">轮播管理</a></li>
        <li class="active">轮播列表</li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="jax-box">
        <form id="formSearch" class="form-horizontal form-search">
            <div class="form-group">
                <div class="col-md-4 col-sm-6">
                    <label class="control-label  col-xs-4" for="keywords" >标题:</label>
                    <div class="col-xs-8">
                        <input type="text" value="" class="form-control" id="keywords">
                    </div>
                </div>
                <shiro:hasPermission name="article:list">
                    <div class="col-md-1 col-sm-6 " style="text-align:left;">
                        <button type="button" id="btn_query" class="btn btn-info">查询</button>
                    </div>
                </shiro:hasPermission>
                <div class="col-md-1 col-sm-6 " style="text-align:left;">
                    <button type="button" id="reset" class="btn btn-info">重置</button>
                </div>
            </div>
        </form>
    </div>
    <div class="jax-box jax-box-table">
        <div id="toolbar" class="btn-group">
            <shiro:hasPermission name="article:add">
            <button id="btn_add" type="button" class="btn btn-primary">
                <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增轮播
            </button>
            </shiro:hasPermission>
            <shiro:hasPermission name="article:batchDelete">
            <button id="btn_batch_delete" type="button" class="btn btn-danger">
                <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>批量删除
            </button>
            </shiro:hasPermission>
        </div>
        <table id="table"></table>
    </div>
</section>
</html>
<script>
    var editFlag = "[[${@perms.hasPerm('article:edit')}]]";
    var deleteFlag = "[[${@perms.hasPerm('article:delete')}]]";
    var columns = [
        {checkbox: true },
        {
            field: 'title',
            title: '标题',
            align : "center"
        },{
            field: 'sort',
            title: '排序',
            align : "center"
        },{
            field: 'enable',
            title: '是否禁用',
            align : "center",
            formatter : function(value) {
               if(value){
                   return '是'
               }else{
                   return '否'
               }
            }
        },{
            field : 'operation',
            title : '操作',
            align : "center",
            class:'min-width-100',
            formatter : function(value,row, index) {
                var edit = editFlag=="true" ? '<a class="table-btn table-btn-info" onclick="editBanner('+row.id+')">编辑</a>' : '';
                var del = deleteFlag=="true" ? '<a  class="table-btn table-btn-danger" onclick="deleteBanner('+row.id+')">删除</a>' : '';
                return edit + del;
            }
        }];
    var options={
        id:"#table",
        url: '/banner/list',
        columns:columns,
        toolbar: '#toolbar',
        showRefresh: true,
        queryParams : queryParams
    }
    Core.initTable(options);
    /*查询参数*/
    function queryParams(params) {
        var temp = { //这里的键的名字和控制器的变量名必须一致，这边改动，控制器也需要改成一样的
            pageNumber: params.pageNumber, // 页码
            pageSize: params.pageSize, // 分页大小
            title : $("#keywords").val(),
            imageId : $("#imageId").val(),//<img alt="图片" th:src="@{/img/noPic.png}" width="240px" height="240px"> $("#imageId").val()
            sort : $("#sort").val(),
            enable : $("#enable").val(),
        };
        return temp;
    }
    /*编辑*/
    function editBanner(id) {
        window.location.href="#banner/edit?id="+id
    }
    /*删除*/
    function deleteBanner(id) {
        Core.confirm("确定删除？",function () {
            Core.postAjax("/banner/delete",{"id":id},function (data) {
                if(data.status==200){
                    Core.refreshTable("#table");
                }
                layer.msg(data.msg);
            })
        })
    }
    $(function () {
        /*查询*/
        $("#btn_query").click(function(){
            Core.refreshTable("#table");
        });
        /*reset*/
        $("#reset").click(function(){
            $("#keywords").val('');
            Core.refreshTable("#table");
        });
        /*新增*/
        $("#btn_add").click(function(){
            window.location.href="#banner/add"
        });
        /*批量删除*/
        $("#btn_batch_delete").click(function(){
            var checkedRows= Core.selectMutiData("#table");
            debugger
            if(checkedRows){
                Core.confirm("确定删除选中的"+checkedRows.length+"条记录？",function () {
                    var ids=[];
                    $.each(checkedRows, function (i, item) {
                        ids.push(item.id);
                    })
                    Core.postAjax("/banner/batchDelete", {"ids": ids}, function (data) {
                        if (data.status == 200) {
                            Core.refreshTable("#table");
                        }
                        layer.msg(data.msg);
                    })
                })
            }
        });
    });
</script>